package com.ecoolex.chinadutyfree.retailer.ws;

import java.util.Calendar;
import java.util.Date;
import java.util.List;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import com.ecoolex.chinadutyfree.retailer.core.manager.DirectMailGoodsOrderIncrementDataManager;
import com.ecoolex.chinadutyfree.retailer.core.manager.DirectMailGoodsOrderTotalDataManager;
import com.ecoolex.chinadutyfree.retailer.core.manager.DirectMailGoodsProductIncrementDataManager;
import com.ecoolex.chinadutyfree.retailer.core.manager.DirectMailGoodsProductTotalDataManager;
import com.ecoolex.chinadutyfree.retailer.core.manager.UserOrderDataManager;
import com.ecoolex.chinadutyfree.retailer.entity.DirectMailGoodsOrderIncrementData;
import com.ecoolex.chinadutyfree.retailer.entity.DirectMailGoodsOrderTotalData;
import com.ecoolex.chinadutyfree.retailer.entity.DirectMailGoodsProductIncrementData;
import com.ecoolex.chinadutyfree.retailer.entity.DirectMailGoodsProductTotalData;
import com.ecoolex.chinadutyfree.retailer.entity.UserOrderData;
import com.ecoolex.chinadutyfree.retailer.pojo.OrderStatisticsIncrementDTO;
import com.ecoolex.framework.common.pojo.Page;
import com.ecoolex.framework.common.pojo.Pagination;
import com.ecoolex.framework.common.pojo.Sorting;

@Service
public class DataAnalyseServiceImpl implements DataAnalyseService{
	
	@Autowired
	private DirectMailGoodsOrderTotalDataManager orderTotalDataManager;
	
	@Autowired
	private DirectMailGoodsOrderIncrementDataManager orderIncrementDataManager;
	
	@Autowired
	private DirectMailGoodsProductTotalDataManager productTotalDataManager;
	
	@Autowired
	private DirectMailGoodsProductIncrementDataManager productIncrementManager;
	
	@Autowired
	private UserOrderDataManager userOrderDataManager;

	@Override
	public DirectMailGoodsOrderTotalData getLatestOrderTotalData() {
		return orderTotalDataManager.getLatest();
	}

	@Override
	public DirectMailGoodsProductTotalData getLatestProductTotalData() {
		return productTotalDataManager.getLatest();
	}

	@Override
	public Pagination<DirectMailGoodsProductIncrementData> queryProductIncrement(Date startDate, Date endDate, String customName, Sorting[] sorts,Page page) {
		return productIncrementManager.queryListByDate(startDate, endDate, customName, sorts, page);
	}

	@Override
	public OrderStatisticsIncrementDTO getOrderIncrementDataByDate(Date startDate, Date endDate) {
		return orderIncrementDataManager.getIncrementDataByDate(startDate, endDate);
	}

	@Override
	public Pagination<UserOrderData> queryUserOrder(Date startDate, Date endDate, Integer userId, Sorting[] sorts, Page page) {
		return userOrderDataManager.queryUserOrder(startDate, endDate, userId, sorts, page);
	}

	@Override
	public List<DirectMailGoodsOrderIncrementData> getIncrementOrderListByDate(Date startDate, Date endDate) {
		return orderIncrementDataManager.incrementDataList(startDate, endDate);
	}

	@Override
	public Boolean refreshOrderTotalData(String updateUser) {
		Long row = orderTotalDataManager.orderTotalData(updateUser);
		if(row>0)
			return true;
		return false;
	}

	@Override
	public Boolean refreshOrderIncrementData(String updateUser, Date statisticsDate) {
		Calendar calendar = Calendar.getInstance();
    	calendar.setTime(statisticsDate);
    	calendar.add(Calendar.DATE,+1);
    	Date nextDate = calendar.getTime();
		Long row = orderIncrementDataManager.orderIncrementData(updateUser, statisticsDate,nextDate);
		if(row>0)
			return true;
		return false;
	}

}
